package utils;

import java.util.List;

import cern.colt.list.DoubleArrayList;
import cern.colt.list.IntArrayList;
import cern.colt.matrix.DoubleFactory2D;
import cern.colt.matrix.DoubleMatrix1D;
import cern.colt.matrix.DoubleMatrix2D;
import cern.colt.matrix.impl.DenseDoubleMatrix1D;

public class StructureTransform {

	public static DoubleMatrix2D vecList2Matrix(List<DoubleMatrix1D> vecList){
		if(vecList==null || vecList.size()==0) return null;
		DoubleMatrix2D res = null;
		if(vecList.get(0) instanceof DenseDoubleMatrix1D) res = DoubleFactory2D.dense.make(vecList.size(), vecList.get(0).size());
		else res = DoubleFactory2D.sparse.make(vecList.size(), vecList.get(0).size());
		IntArrayList indexList = new IntArrayList();
		DoubleArrayList valueList = new DoubleArrayList();
		for(int i=0;i<vecList.size();i++){
			vecList.get(i).getNonZeros(indexList, valueList);
			for(int j=0;j<indexList.size();j++) res.setQuick(i, indexList.get(j), valueList.get(j));
		}
		return res;
	}
	
}
